import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
import packageJson from './package.json'
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
import vueJsx from '@vitejs/plugin-vue-jsx'

export default defineConfig({
  define: {
    'process.env': {
      VUE_APP_VERSION: packageJson.version,
      VUE_APP_LANG: 'LANGUAGE',
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    createSvgIconsPlugin({ // 一次性导入SVG图片
      iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
      symbolId: 'icon-[name]'
    })
  ],
  base: './',
  publicDir: 'public',
  clearScreen: true,
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
    extensions:['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
  },
  optimizeDeps: {
    force: false
  },
  json: {
    namedExports: true,
    stringify: false,
  },
  server: {
    host: '0.0.0.0',
    https: false,
    cors: true,
    port: 23333,
    strictPort: false,
    force: true,
    hmr: false,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:18221',
        changeOrigin: true,
        secure: false,
        rewrite: path => path.replace(/^\/api/, '')
      }
    }
  },
  build: {
    target: 'modules',
    outDir: 'dist',
    assetsDir: 'assets',
    assetsInlineLimit: 4096,
    cssCodeSplit: true,
    sourcemap: false,
    minify: 'terser',
    write: true,
    emptyOutDir: true,
    brotli: true,
    brotliSize: true,
    chunkSizeWarningLimit: 1024,
    cssMinify: true,
    cssInlineLimit: 4096,
  }
})
